Page({
    data: {
        query: '',

        active: '0',

        doctors: [],
        drugs: [],
        hospitals: []
    },

    onLoad: function(options) {
        this.setData({active: options.category || 0})
        this.onSearch()
    },

    onChangeQuery(ev){
        this.data.query = ev.detail
    },
    
    onSearch: function() {
        var self = this

        if (self.data.active == "0") {
            wx.request({
                url: 'https://www.srdb.com/drug',
                success:function(res){
                self.setData({drugs: self.data.drugs.concat(res.data)})
                }
            })
        } else if (self.data.active == "1") {
            wx.request({
                url: 'https://www.srdb.com/doctor',
                success:function(res){
                self.setData({doctors: self.data.doctors.concat(res.data)})
                }
            })
      } else {
            wx.request({
                url: 'https://www.srdb.com/hospital',
                success:function(res){
                self.setData({hospitals: self.data.hospitals.concat(res.data)})
                }
            })
      }
    },

    onChange: function(ev) {
        this.data.active = "" + ev.detail.index

        this.onSearch()
    }
})
  
  